﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContractListCtrl.ascx.cs" Inherits="WebUI.Controls.ContractListCtrl" %>


<script type="text/javascript">
    var <%=ClientID %>clickOnCheckbox;
    var <%=ClientID %>selectedRow = null;       
    var <%=ClientID %>selectedCheckbox = null; 
    var <%=ClientID %>selectedID = null; 
    var <%=ClientID %>selectedClass = null; 
    
    function resetGridSelection<%=ClientID %>(){
        <%=ClientID %>selectedRow = null;   
        if(<%=ClientID %>selectedCheckbox != null)
            <%=ClientID %>selectedCheckbox.checked = false;          
        <%=ClientID %>selectedCheckbox = null; 
        <%=ClientID %>selectedID = null; 
        <%=ClientID %>selectedClass = null; 
    }
    
    function clickOnCheckBox<%=ClientID %>(cb){
        <%=ClientID %>clickOnCheckbox = true;
    }
    
    function onItemClick<%=ClientID %>(sender)
    {
        var hidSelectedID = document.getElementById("<%= hidSelectedID.ClientID %>");
        if(<%=ClientID %>clickOnCheckbox){
            <%=ClientID %>clickOnCheckbox = false;
            return;
        }

        if(<%=ClientID %>selectedRow == null){
            <%=ClientID %>selectedRow = document.getElementById("<%=ClientID %>" + "_row_" + hidSelectedID.value);
        }
        
        if(<%=ClientID %>selectedRow != null){
            if(<%=ClientID %>selectedRow.className)
                <%=ClientID %>selectedRow.className = <%=ClientID %>selectedRow.getAttribute("orgclass");
            else
                <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
            if(<%=ClientID %>selectedCheckbox != null)
                <%=ClientID %>selectedCheckbox.checked = false;
            else{
                var chks = <%=ClientID %>selectedRow.getElementsByTagName("input");
                 for(var i = 0; i < chks.length; i++){
                    if(chks[i].type == "checkbox" && chks[i].id.indexOf("cbSelect") >= 0){
                        chks[i].checked = false;
                        break;
                    }
                }
            }
        }
        
        if(sender.className){
            sender.className = "CustomGridSelectedItem";
        }
        else{
            <%=ClientID %>selectedClass = sender.getAttribute("class");
            sender.setAttribute("class", "CustomGridSelectedItem");
        }
        <%=ClientID %>selectedRow = sender;
        
        var inputs = sender.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
                <%=ClientID %>selectedCheckbox = inputs[i];
                inputs[i].checked = true;
                break;
            }
        }

        hidSelectedID.value = <%=ClientID %>selectedRow.getAttribute("ItemID");
    }
    
    function selectAll<%=ClientID %>(cbAll){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox"){
                inputs[i].checked = cbAll.checked;
            }
        }
    }
    
    function getSelectedItemID<%=ClientID %>(){
        if(document.getElementById("<%= hidSelectedID.ClientID %>").value == "")
            return null;
        return document.getElementById("<%= hidSelectedID.ClientID %>").value;
    }

    function showPrintDlg(key) {
        var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
    }

    function onInvoiceNo_click(lnk){
        var hidInvoiceID = document.getElementById("<%= hidInvoiceID.ClientID %>");     
        hidInvoiceID.value = lnk.getAttribute('ItemID');
    }
</script>



<%--start modify here--%>
<asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None" class="customGrid" ShowHeader="false"
    AutoGenerateColumns="false" EmptyDataText="No record to display" ItemStyle-Wrap="true" CellPadding="0" CellSpacing="0"
    OnSortCommand="grid_OnSortCommand" OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound"
    OnPageIndexChanged="grid_OnPageIndexChanged" AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
    <PagerStyle Mode="NumericPages" PageButtonCount="10"   />
    <Columns>
        <asp:TemplateColumn ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
            <ItemTemplate>
                <asp:CheckBox ID="cbSelect" runat="server" ItemID='<%# Eval("ID") %>' />
            </ItemTemplate>
            <ItemStyle VerticalAlign="Top" />
        </asp:TemplateColumn>
        
        <asp:TemplateColumn HeaderText="">
            <ItemStyle VerticalAlign="Top" />
            <ItemTemplate>
                <table width="100%" style="vertical-align:top">
                    <tr>
                        <td style='width:150px; text-align:left; vertical-align:top'>
                            <asp:Label class="labelBarCode" ID="Label1" runat="server" Text="CNT:"></asp:Label> 
                            <asp:Label class="labelBarCode" ID="Label2" runat="server" Text='<%# Eval("ContractNo") %>' ></asp:Label>
                            <br /> 
                            <div class='labelBarCode'><asp:Literal  ID="litContractNo" runat="server" Text='<%# POSSystem.BLL.Utilities.GenerateBarCode(Eval("ContractNo").ToString()) %>' ></asp:Literal></div>
                            <asp:Label class="labelBarCode" ID="Label4" runat="server" Text='<%# ((DateTime)Eval("ContractCreatedDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat) %>' ></asp:Label>
                            
                            <br /><br /><br /><br /><br />
                            <asp:Label class="labelBarCode" ID="Label14" runat="server" Text='<%# "by " +  Eval("SaleUserFullName") %>' ></asp:Label>
                        </td>
                        
                        <td style='width:550px; text-align:left; vertical-align:top'>
                            <asp:Label class="labelMessage1" ID="Label5" runat="server" Text='<%# Eval("CustomerName") %>' ></asp:Label> 
                            <div style='height:10px' > &nbsp; </div>
                            <asp:Label class="labelMessage0" ID="Label6" runat="server" Text='<%# Eval("NetworkName") %>' ></asp:Label> 
                            <asp:Label class="labelMessage0" ID="Label7" runat="server" Text='<%# Eval("MobileNumber").ToString() != "" ? ("#" + Eval("MobileNumber")) : "" %>' ></asp:Label>
                            <br />
                            <asp:Label class="labelMessage" ID="Label3" runat="server" Text='<%# Eval("ProductName") %>' ></asp:Label>
                            <asp:Label class="labelMessage" ID="Label8" runat="server" Text=' - ' ></asp:Label>
                            <asp:Label class="labelMessage" ID="Label10" runat="server" Text='<%# Eval("IMEI") %>' ></asp:Label> &nbsp;&nbsp;&nbsp;
                            <asp:Label class="labelMessage" ID="Label9" runat="server" Text='<%# String.Format("{0:C}", Eval("Cost")) %>' ></asp:Label>
                            <br />
                            <asp:Label class="labelMessage" ID="Label11" runat="server" Text='<%# Eval("PlanDescription") %>' ></asp:Label>
                            <asp:Label class="labelMessage" ID="Label12" runat="server" Text='<%# Eval("PlanDescription").ToString() != "" ? (" - " + Eval("PlanDuration") + " months") : (Eval("PlanDuration") + " months") %>' ></asp:Label>
                            <asp:Label class="labelMessage" ID="Label27" runat="server" Text='<%# "(" + (Eval("ContractStartDate") == DBNull.Value ? "n/a" : ((DateTime)Eval("ContractStartDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat)) %>' ></asp:Label>
                            <asp:Label class="labelMessage" ID="Label30" runat="server" Text='-' ></asp:Label>
                            <asp:Label class="labelMessage" ID="Label32" runat="server" Text='<%# (Eval("ContractEndDate") == DBNull.Value ? "n/a" : ((DateTime)Eval("ContractEndDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat)) + ")" %>' ></asp:Label>
                            <br />
                            <asp:Label class="labelMessage0" ID="Label15" runat="server" Text='Payment Status:' ></asp:Label> &nbsp;&nbsp;
                            <asp:Label class="labelMessage0" ID="Label17" runat="server" Text='COM:' ></asp:Label> 
                            <asp:Label class="labelMessage0" ID="Label16" runat="server" Text='<%# String.Format("{0:C}", Eval("Commission")) %>' ></asp:Label> 
                            <asp:Label class="labelMessage0" ID="Label18" runat="server" Text='MPP:' ></asp:Label> 
                            <asp:Label class="labelMessage0" ID="Label19" runat="server" Text='<%# String.Format("{0:C}", Eval("MPP")) %>' ></asp:Label> 
                            <asp:Label class="labelMessage0" ID="Label20" runat="server" Text='Rebate:' ></asp:Label> 
                            <asp:Label class="labelMessage0" ID="Label21" runat="server" Text='<%# String.Format("{0:C}", Eval("Rebate")) %>' ></asp:Label> 
                            <br />
                            <table style="border-color:Green; border-bottom-style:dotted; border-bottom-width:1px;border-top-style:dotted; border-top-width:1px;">
                                <tr>
                                    <td style='padding-left:40px; text-align:left; width:150px; vertical-align:top' ><asp:Label class="labelMessage" ID="Label22" runat="server" Text='Commission Due:' ></asp:Label></td>
                                    <td style='text-align:right; width:150px; vertical-align:top' >
                                        <asp:Label style='color:#990000' class="labelMessage0" ID="Label24" runat="server" Text='<%# String.Format("{0:C}", Eval("TotalAmount")) %>' ></asp:Label> 
                                    </td>
                                </tr>
                                <tr>
                                    <td style='padding-left:40px;text-align:left; width:150px; vertical-align:top' ><asp:Label class="labelMessage" ID="Label23" runat="server" Text='Commission Paid:' ></asp:Label></td>
                                    <td style='text-align:right; width:150px; vertical-align:top' >
                                        <asp:Label style='color:#990000' class="labelMessage0" ID="Label25" runat="server" Text='<%# String.Format("{0:C}", Eval("PaidAmount")) %>' ></asp:Label> 
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" style='text-align:right; vertical-align:top' >
                                        <asp:Label class="labelMessage" ID="Label26" runat="server" Text='Balance on' ></asp:Label>
                                        <asp:LinkButton ID="lnkInvoiceNo" class='hintBold' runat="server" Text='<%# "#" + Eval("InvoiceNo") %>' OnClientClick='onInvoiceNo_click(this); return true;' OnClick="btnPrint_OnClick" ItemID='<%# Eval("InvoiceID") %>'></asp:LinkButton>
                                        &nbsp;&nbsp;&nbsp;
                                        <asp:Label style='color:#990000' class="labelMessage0" ID="Label28" runat="server" Text='<%# String.Format("{0:C}", Math.Round((Decimal)Eval("TotalAmount") - (Decimal)Eval("PaidAmount"), 2)) %>' ></asp:Label>
                                    </td>
                                </tr>
                            </table>

                        </td>
                        
                        <td style='text-align:left; vertical-align:top'>
                            <asp:Button ItemID='<%# Eval("ID") %>' Text="Update Status" ID="btnUpdateMemo" runat="server" OnClientClick="return false;" />
                        </td>
                    </tr>
                    <tr>
                        <td style='text-align:right; vertical-align:top'>
                            
                        </td>
                        <td style='text-align:right; vertical-align:top'>
                            <div style='height:10px'></div>
                        </td>
                        <td></td>
                    </tr>
                    <tr>
                        <td style='text-align:right; vertical-align:top'>
                            <asp:Label class="labelMessage0" ID="Label13" runat="server" Text='Memo:' ></asp:Label> 
                        </td>
                        <td style='text-align:left; vertical-align:top'>
                            <div class="labelNote"><asp:Literal ID="litMemo" runat="server" Text='<%# Eval("Memo") %>' ></asp:Literal></div>
                        </td>
                         <td></td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:TemplateColumn>
    </Columns>
</asp:DataGrid>
<asp:HiddenField ID="hidInvoiceID" runat="server" />
<asp:HiddenField ID="hidSelectedID" runat="server" />